(* Copyright Per Lindgren 2014, see the file "LICENSE" *)
(* for the full license governing this code.           *)

(* FUN-4SURE/Options *)

open Common

type options = 
  {
   mutable verbose:     bool;
   mutable debug:       bool;
   mutable infile:      string;
   mutable gv_ecc:      bool;
   mutable gv_eccf:     string;
   mutable why:         bool;
   mutable why_il:      bool;
   mutable whyf:        string;
   mutable gv_if:       bool;
   mutable d_ast:       bool;
   (* mutable string:   Time.t; -- not yet implemented *)
  }
  
let opt = 
  {
   verbose   = false;
   debug     = false;
   infile    = "";
   gv_ecc    = false;
   gv_eccf   = "";
   gv_if     = false;
   why       = false;
   why_il    = false;
   whyf      = "";
   d_ast     = false;
  } 
    
    
let string_of_opt opt = 
  "RTFM-core options:" ^ nl ^  
  "infile       : " ^ opt.infile ^ nl ^
  "verbose      : " ^ string_of_bool opt.verbose ^ nl ^
  "debug        : " ^ string_of_bool opt.debug ^ nl ^
  "gv_ecc       : " ^ string_of_bool opt.gv_ecc ^ nl ^
  "gv_eccf      : " ^ opt.gv_eccf ^ nl ^
  "gv_if        : " ^ string_of_bool opt.gv_if ^ nl ^
  "why          : " ^ string_of_bool opt.why ^ nl ^
  "why_il       : " ^ string_of_bool opt.why_il ^ nl ^
  "whyf         : " ^ opt.whyf ^ nl ^
  "d_ast        : " ^ string_of_bool opt.d_ast ^ nl

let verb s  = if opt.verbose then p_stderr ("-- " ^ s ^ " -- ")
let debug s = if opt.debug then p_stderr ("   DEBUG >> " ^ nl ^ s ^ nl ^ "<< DEBUG ")

let timed s f g = 
  (* verb ("---> " ^ s ^ ":"); *)
  let t = Sys.time() in
  let res = f g in
  let sfloat = Printf.sprintf "%.3f" (Sys.time() -. t) in
  verb ("---> " ^ s ^ ": finished in " ^ sfloat ^ "s.");
  res
  